#pragma once
#include "base/core/singleton.h"
#include "base/core/object_pool.h"
#include "base/core/point3.h"
#include "Common/Event/Event.h"
#include "Common/TableData/DropDropCfg.h"
#include "Common/TableExDefine.h"
#include "Scene/SceneMgr.h"
#include "Common/Item/ItemMgr.h"
#include "Object.h"
#include <map>

class ObjectMgr : public ManualSingleton < ObjectMgr >
{
	friend class ManualSingleton < ObjectMgr >;
	//typedef unordered_map<CharIDType, Object*> MapObject;
	typedef unordered_map<uint32_t, MAP_UINT32_SET_INT32> MapSceneObject;
	//typedef std::unordered_map<uint32_t, MAP_UINT32_SET_UINT64> MapSceneFresh;
	typedef std::unordered_map<uint32_t, MAP_UINT32_MULTI_SET_UINT64> MapSceneFresh;

public:
	ObjectMgr();
	virtual ~ObjectMgr();

public:
	bool				Init();
	bool				UnInit();
	bool				Update(uint64_t tick);
	Object*				CreateObject(uint32_t nObjectId, uint32_t nSceneId, Point3<float>& bornPos, int32_t posIdx);
	Object*				CreateObjectByChar(uint32_t nObjectId, uint32_t nSceneId, Point3<float>& bornPos, CharIDType charId);
	bool				CollectScuess(Creature *creat, bool fresh = true);
	void				Add2FreshMap(Object *pObject);
	void				InitSceneObject(const LstCollectCfg &objectLst, uint32_t mapId, uint32_t sceneId);

private:
	bool				CheckPeel(Creature *creat);			//剥皮类不走刷新流程
	bool				CheckRecycle(Object *pObject);		//采集次数耗尽时方可移除
	bool				FreshObject(uint32_t sceneId, uint32_t objectId);
	SET_INT32*			GetSceneObject(uint32_t sceneId, uint32_t ObjectId);
	bool				FreshObject(const ThingCollectCfgInfo *pCollectCfg, uint32_t mapId, uint32_t sceneId, uint32_t objectId, uint32_t count);

private:
	MapSceneObject		m_mapSceneObject;			//统计每个场景中的矿物件的ID，便于后面刷新新的矿物件
	MapSceneFresh		m_mapSceneFresh;			//记录每个场景需要刷新的矿物件时间
	//MAP_UINT32_LST_UINT64 m_mapSceneBrushTick;
};

#define g_MakeObjectMgr()	(ObjectMgr::Instance())
#define g_GetObjectMgr()	(ObjectMgr::GetInstance())
#define g_DelObjectMgr()	(ObjectMgr::Destroy())